/**
 * Commented
 * @author Nicola Salvo
 */
package gsoc.ogsadai.model.diagram.edit.helpers;

import gsoc.ogsadai.model.ModelFactory;
import gsoc.ogsadai.model.ModelPackage;
import gsoc.ogsadai.model.ParallelType;
import gsoc.ogsadai.model.WorkflowType;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;

/**
 * This helper class is used to automagically create a workflow type element when a 
 * ParallerType element is created. This code snippet shows a good example of how to
 * use  custom commands  
 */

/**
 * @generated NOT
 */
public class ParallelTypeEditHelper extends RequestBaseEditHelper {
	/*
	 * (non-Javadoc)
	 * 
	 * @seeorg.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper#
	 * getConfigureCommand
	 * (org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest)
	 */
	@Override
	protected ICommand getConfigureCommand(final ConfigureRequest req) {
		return new ConfigureElementCommand(req) {
			protected CommandResult doExecuteWithResult(
					IProgressMonitor monitor, IAdaptable info)
					throws ExecutionException {
				EObject element = req.getElementToConfigure();

				doConfiguration(element, monitor);
				return CommandResult.newOKCommandResult(element);
			}
		};
	}

	/**
	 * 
	 * @param element
	 * @param monitor
	 */
	protected void doConfiguration(EObject element, IProgressMonitor monitor) {
		ParallelType pt = (ParallelType) element;

		// fetch the container of the Subtopic
		EReference parallelContainer = ModelPackage.eINSTANCE
				.getParallelType_Workflow();
		// take the Factory and create the Subtopic
		WorkflowType wtObj = ModelFactory.eINSTANCE.createWorkflowType();
		EClass workflowClass = wtObj.eClass();
		// create the Subtopic
		EObject condition = EMFCoreUtil.create(pt, parallelContainer,
				workflowClass);
	}
}